package mce.web.controller;

import mce.web.controller.model.FirstDataModel;
import mce.web.controller.model.FirstDataUtil;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

@Controller
@RequestMapping("/firstdata-payment")
@SessionAttributes("firstDataModel")
public class PaymentController {
	
	@RequestMapping(method = RequestMethod.POST)
    public ModelAndView pay(
    		@RequestParam("transactionType") final String transactionType,
    		@RequestParam("paymentMethod") final String paymentMethod,
    		@RequestParam("paymentMode") final String paymentMode,
    		@RequestParam("transactionOrigin") final String transactionOrigin,
    		@RequestParam("orderId") final String orderId,
    		@RequestParam("transactionDate") final String transactionDate,
    		@RequestParam("chargeTotal") final String chargeTotal,
    		@RequestParam("subTotal") final String subTotal
    		) {
		FirstDataUtil firstDataUtil = new FirstDataUtil();
		String calculatedHash = firstDataUtil.createHash(chargeTotal);
		FirstDataModel firstDataModel = new FirstDataModel();
		/* Set attribute for firstDataModel */
		firstDataModel.setTimezone(firstDataUtil.getTimeZone());
		firstDataModel.setAuthenticateTransaction(false);
		firstDataModel.setPaymentMethod(paymentMethod);
		firstDataModel.setTxntype(transactionType);
		firstDataModel.setTxndatetime(firstDataUtil.getFmtDate());
		firstDataModel.setHash(calculatedHash);
		firstDataModel.setMode(paymentMode);
		firstDataModel.setStorename(firstDataUtil.getStoreName());
		firstDataModel.setChargetotal(chargeTotal);
		firstDataModel.setSubtotal(subTotal);
		firstDataModel.setTrxOrigin(transactionOrigin);
		firstDataModel.setIod(orderId);
		firstDataModel.setTdate(transactionDate);
		firstDataModel.setResponseSuccessURL("http://mpayplus.net/mce.demo/create-order/order-completed");
		return new ModelAndView("Payment","firstDataModel",firstDataModel);
    }
}



















